import axios from '@/utils/http';
import base from './base';

export default {
  // 问题列表
  index(params) {
    return axios.get(
      `${base.sq}/products/${params.spaceId}/issues`,
      {
        params: {
          select_type: params.type, // 当前已失效
          essence: params.isGood,
          page: params.page,
          order_type: params.sort,
          order_action: params.order,
        },
      },
    );
  },
  // 问题展示
  show(params) {
    return axios.get(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}`,
    );
  },
  // 创建问题
  create(params) {
    return axios.post(
      `${base.sq}/products/${params.spaceId}/issues`,
      {
        title: params.title,
        content: params.content,
        reminder: params.remindersId,
        tag_titles: params.tags,
      },
    );
  },
  // 更新问题
  update(params) {
    return axios.put(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}`,
      {
        title: params.title,
        content: params.content,
        reminder: params.remindersId,
        tag_titles: params.tags,
      },
    );
  },
  // 删除问题
  delete(params) {
    return axios.delete(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}`,
    );
  },
  // 设置精华
  essence(params) {
    return axios.post(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}/essence`,
      {
        set: params.state,
      },
    );
  },
  // 日志
  log(params) {
    return axios.get(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}/logs`,
      {
        params: {
          page: params.page,
          per_number: params.number,
        },
      },
    );
  },
  // 接受回答
  accept(params) {
    return axios.post(
      `${base.sq}/products/${params.spaceId}/issues/${params.issueId}/accept_answer`,
      {
        comment_id: params.commentId,
      },
    );
  },
};
